package com.tianqu.tms.www.car.controller;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsController;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.dto.MarketCarInfoChe300;
import com.tianqu.tms.entity.Car;
import com.tianqu.tms.www.car.viewhelper.CarQRCodePrintViewHelper;

public class CarQRCodePrintController extends TmsController {
	private Logger LOGGER = Logger.getLogger(CarQRCodePrintController.class);
	@Override
	public void execute(UserContext uc) throws Exception {
		LOGGER.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = TxController.getTxController();
		// 添加事务提交异常捕获
		try {
			String serial = (String)uc.getAttribute("serial");
			MarketCarInfoChe300 carInfo = Car.getInstance().getCarInfobySerial(serial);
			if(carInfo != null) {
				uc.setAttribute("brandName",carInfo.getSeries());
				uc.setAttribute("vin",carInfo.getVin());
			}else{
				LOGGER.error("not found car info,serial:"+serial);
				uc.setAttribute("brandName","");
				uc.setAttribute("vin","");
			}
		} catch (Exception e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
			// 系统异常
			if (e instanceof TmsException) {
				throw e;
			}
			throw new TmsException(TmsException.DB_TXCRROR, e);
		}

		LOGGER.debug(this.getClass().getName() + "#execute was completed.");
	}
}
